from common.recording import selfmethod_desc
from common.core.page import BasePage
from common.core import wait


class WelcomePage(BasePage):
    page_path = "portal/market/all"
    page_name = "游客页"
    elements = "客户端", "游客.yaml"

    @selfmethod_desc("用户登录 | <login_data['username']>", alias="登录操作")
    def login(self, login_data: dict):
        # self.action_chains.move_to_element(
        #     "控制台",
        #     callback=lambda this: wait.SingleElementEnabled("移动云控制台").wait()
        # ).click("移动云控制台").perform()
        # self["账号登录"].click()

        self.func_alias("动作链").params()\
            .func_alias("动作链悬停").params("控制台", callback=lambda this: wait.SingleElementEnabled("移动云控制台").wait())\
            .func_alias("动作链点击").params("移动云控制台")\
            .perform()
        self["账号登录"].func_alias("点击").params()
        self["用户名输入框"].send_keys(login_data["username"])
        self["密码输入框"].send_keys(login_data["password"])
        self["确认服务条款"].click()
        self["用户登录按钮"].click()

    @selfmethod_desc("进入 <module_name> 模块页面", alias="进入模块页面")
    def to_module(self, module_name: str):
        self.action_chains. \
            move_to_element("控制台",
                            callback=lambda this: wait.SingleElementEnabled("移动云控制台").wait()). \
            click("移动云控制台").perform()
        self["产品与服务"].click()
        self[module_name].click()
